﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

namespace Royaume
{
    public partial class CreationPersonnage : System.Web.UI.Page
    {
        cSql objSql=new cSql("(local)","DB_GAME","RoyaumesLibres","123456");
        Dictionary<SqlParameter, object> param = new Dictionary<SqlParameter, object>();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["pkUser"] == null)
            {
                Response.Redirect("WebForm1.aspx");
            }
            this.RadioButtonListRace.AutoPostBack = true;
            this.RadioButtonListAlignement.AutoPostBack = true;

            if (!Page.IsPostBack)
            {
                this.RadioButtonListAlignement.SelectedIndex = 0;
                this.lblDescription.Text = "+3 nourriture / fermier, rabais de 15% sur unités archers";
                this.RadioButtonListRace.SelectedIndex = 0;
            } 
        }

        protected void RadioButtonListRace_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (RadioButtonListRace.SelectedItem.Value == "Humain") {
                this.lblDescription.Text = "+2 bois/bûcheron et la population augmente 20% plus rapidement.";

            }else if (RadioButtonListRace.SelectedItem.Value == "Mystic") {
                this.lblDescription.Text = "+1 minerais/mineur, rabais de 15% sur unités volantes";

            } else if (RadioButtonListRace.SelectedItem.Value == "Nain"){
                this.lblDescription.Text = "+2 minerais/mineur, rabais de 15% sur unités de mêlée";

            }else if (RadioButtonListRace.SelectedItem.Value == "Elfe"){
                this.lblDescription.Text = "+3 nourriture/fermier, rabais de 15% sur unités archers";
            }
        }

        protected void btnCreerPerso_Click(object sender, EventArgs e)
        {
            try
            {
                param.Clear();
                param.Add(new SqlParameter("@FkMembre", SqlDbType.Int), Session["pkUser"]);
                param.Add(new SqlParameter("@Race", SqlDbType.VarChar, 50), RadioButtonListRace.SelectedItem.Value.ToString());
                param.Add(new SqlParameter("@Alignement", SqlDbType.VarChar, 25), RadioButtonListAlignement.SelectedItem.Value.ToString());

                objSql.fnStoredProc("spInsertJoueurSelonRace", param);

                //A modifier la redirection 
                Response.Redirect("map.aspx");
            }
            catch (Exception) {
                cUtility.fnMsgBox("Vous avez déja créé votre personage!!!", Page);
            }


        }
    }
}